<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var today = new Date()
        console.log(today)

        var year = today.getFullYear()
        var month = addZero(today.getMonth()+1)
        var day = addZero(today.getDate())
        var hour = addZero(today.getHours())
        var minute = addZero(today.getMinutes())
        var second = addZero(today.getSeconds())

        var currentTime = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
        console.log(currentTime)

        /**
         * 对个数位进行补0操作
         */ 
        function addZero(num){
            return num < 10 ? '0'+num : num
        }
    </script>
</body>
</html>